﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tanmia.Core;
using FluentNHibernate.Mapping;

namespace Tanmia.NHibernate.Mapping
{
    public class PersonMap : ClassMap<Person>
    {
        public PersonMap()
        {
            Table("Person");

            Id(x => x.PersonID).Not.Nullable().GeneratedBy.Identity();

            Map(x => x.Name).Not.Nullable().Unique().Length(128);
            Map(x => x.PersonType).Not.Nullable().CustomType<PersonTypeEnum>();
            Map(x => x.CreateDate).Not.Nullable().Not.Update();
            Map(x => x.Note).Nullable().Length(2048);

            References(x => x.Account, "AccountID").Nullable();

            HasMany(x => x.Details).KeyColumn("PersonID").Cascade.SaveUpdate();
        }
    }
}
